package com.zyg.jas.studentport.controller;

import com.zyg.jas.common.pojo.Article;
import com.zyg.jas.common.pojo.LeaveWords;
import com.zyg.jas.studentport.service.LeaveWordsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("/sport/leavewords")
public class LeaveWordsController {
    private static  final Logger logger = LoggerFactory.getLogger(LeaveWordsController.class);

    @Autowired
    private LeaveWordsService leaveWordsService;

    @RequestMapping(value = "/addComment",method = RequestMethod.POST)
    @ResponseBody
    public void addComment(LeaveWords leaveWords){
        logger.info(leaveWords.toString());
        this.leaveWordsService.addWords(leaveWords);
    }

    //查询本篇文章下的评论
    @RequestMapping(value = "/getComment/{lw_aid}",method = RequestMethod.GET)
    @ResponseBody
    public List<LeaveWords> getMyArticle(@PathVariable("lw_aid") String pId){
        return this.leaveWordsService.searchWords(pId);
    }

    //删除一个评论
    @RequestMapping(value = "/deleteComment/{id}")
    @ResponseBody
    public void deleteComment(@PathVariable("id") Integer id){
        this.leaveWordsService.delById(id);
    }

}
